﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization;
using System.Web;

namespace ExampleControlWeb
{
    /// <summary>
    /// Summary description for NearMapsJsonHandler
    /// </summary>
    public class NearMapsJsonHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var url = @"http://www.nearmap.com/maps/x={0}&y={1}&z={2}&nmq=INFO&nmf=json"; //&nmjsonp=jsonp1267176209643";
            var x = context.Request.QueryString["x"];
            var y = context.Request.QueryString["y"];
            var z = context.Request.QueryString["z"];

            url = string.Format(url, x, y, z);

            var wc = new WebClient();

            context.Response.Clear();
            context.Response.ContentType = "application/jsonrequest";

            try
            {
                var data = wc.DownloadString(url);
                context.Response.Write(data);
            }
            catch (Exception)
            {
                
            }
            finally
            {
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }


    //[DataContract]
    //public class NearMapLayers
    //{
    //    [DataMember(Name = "layers")]
    //    public NearMapVert Layers { get; set; }
    //}

    //[DataContract]
    //public class NearMapVert
    //{
    //    //[DataMember(Name = "layers")]
    //    //public int Layers { get; set; }

    //    [DataMember(Name = "Vert")]
    //    public Array Vert { get; set; }
    //}

}